package com.dinner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dinner.entity.DiCar;
import com.dinner.mapper.DiCarMapper;
import com.dinner.mapper.DiMenuMapper;
import com.dinner.mapper.DiUserMapper;
import com.dinner.service.DiCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dinner
 * @since 2022-02-16
 */
@Service
public class DiCarServiceImpl extends ServiceImpl<DiCarMapper, DiCar> implements DiCarService {
    @Autowired
    DiCarMapper diCarMapper;
    @Autowired
    DiUserMapper diUserMapper;
    @Autowired
    DiMenuMapper diMenuMapper;
    @Override
    public List<DiCar> findCar(int size, int current,int userId) {
        Page<DiCar> page=new Page<>(size,current);
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("user_id",userId);
        Page<DiCar> pages=diCarMapper.selectPage(page,wrapper);
       List<DiCar> list= pages.getRecords();
       for(DiCar a:list){
           a.setDiUser(diUserMapper.selectById(a.getUserId()));
           a.setDiMenu(diMenuMapper.selectById(a.getMenuId()));
       }
       return list;
    }
}
